<template>
  <h6 style="color: crimson">商品与赠品管理--><a href="http://localhost:5173/gift">赠品管理</a>-->提交赠品转商品</h6>
<el-button type="primary" icon="Pointer" @click="chooseGift">选择赠品</el-button><br>
        赠品名称:  <br>{{uModel.giftName}}
  <hr> 赠品类型:  <br>{{uModel.giftType}}
  <hr> 赠品型号:  <br>{{uModel.giftModel}}
  <hr> 赠品单价:  <br>{{uModel.marketPrice}}
  <hr> 采购成本:  <br>{{uModel.purchasePrice}}
  <hr> 赠品数量:  <br>{{uModel.giftNum}}
  <hr> 最低库存: <br>{{uModel.minStock}}
  <el-form-item label="输入入库数" prop="num" >
    <el-input v-model="uModel.count" placeholder="数量" />
  </el-form-item>
  <el-button type="primary" @click="submit">
    提交
  </el-button>
</template>

<script setup>
import {ref,reactive,onMounted,getCurrentInstance} from "vue";
import axios from "@/plugins/axios.js";
import {ElMessage} from "element-plus";
import router from "@/router/index.js";
import {giftStore} from "@/stores/GiftModel.js";
import {
  Plus,Search,Delete,Check,Right,Pointer
} from '@element-plus/icons-vue'
const giftModel = giftStore();

const uModel=ref({
  id:'',
  giftName:'',
  giftType:'',
  giftModel:'',
  marketPrice:'',
  purchasePrice:'',
  giftNum:'',
  minStock:'',
  count:''
})
const subForm=ref({
  giftId:'',
  count:''
})
const submit = () => {
  subForm.value.count=uModel.value.count;
  subForm.value.giftId=uModel.value.id;
  axios.postJson('/gift2goods/addGift2Goods', subForm.value).then(res=>{
    console.log(res)
    if(res.code==200){
      ElMessage.success("添加成功")
      router.push({
        path:"/gift/gift2goods",
      })
    }
  })
}

const chooseGift = () => {
router.push({
  path:"/gift/choose",
})
  console.log(giftModel.userModel)
}
onMounted(() => {
  console.log(giftModel.userModel)
  if(giftModel.userModel!=undefined){
  uModel.value=giftModel.userModel;
  }
});

</script>

<style >

</style>